/*
 *  Description: BOAT XU SOFT FHSS
 *  Version: V1.00
 *  Author: boat xu
 *  Email: xifengzui@outlook.com
 *  Date: 2020-07-14 13:39:19
 *  LastEditTime: 2020-07-18 14:31:00
 */ 
#include "string.h"
#include "bsf_types.h"
#include "bsf_itypes.h"
#include "bsf_debug.h"
#include "bsf.h"
#include "bsf_freqHopping.h"
bsf_FreqHopping fh;
void bsf_freqHopping_init(bsf_FreqHopping *fhi)
{
    dprintf("   CALL:bsf_freqHopping_init");
    if(fhi == b_null)
    {
        fh.seed = BSF_RAND_DEFAULT_SEED;
        fh.loopLen = BSF_RAND_DEFAULT_LOOP_LEN;
        fh.index = 0;
        bsf_rand_init();
    }
    else
    {
        memcpy(&fh,fhi,sizeof(bsf_FreqHopping));
        bsf_rand_set(fh.seed,b_null);
    }
}
void bsf_freqHopping_set(b_u16_t seed,b_u8_t *table)
{
    bsf_rand_set(seed,table);
}
void bsf_freqHopping_reset(void)
{
    bsf_rand_set(fh.seed,b_null);
}

void bsf_freqHopping_resetDefault(void)
{
    bsf_rand_set_default();
}

void bsf_freqHopping_jumpToNext_loop(void)
{
    fh.index++;

    if(fh.index >= fh.loopLen)
    {
        fh.index = 0;
        bsf_freqHopping_reset();
    }
    fh.freq = bsf_rand_Next();
    SetFreq(fh.freq);
}

void bsf_freqHopping_jumpToNext(void)
{
    fh.freq = bsf_rand_Next();
    SetFreq(fh.freq);
}

void bsf_freqHopping_lowerWeight(void)
{
    bsf_rand_loss(fh.freq);
}

void bsf_freqHopping_recoverWeight(void)
{
    bsf_rand_recover();
}

void bsf_freqHopping_setToShadowTable(void)
{
    bsf_rand_set(fh.seed,b_null);
    bsf_rand_update();
}

b_u8_t *bsf_freqHopping_getShadowTable(void)
{
    return shadow_table;
}
b_u16_t bsf_freqHopping_getSeed(void)
{
    return fh.seed;
}